<template>
  <div class="page_recruitStaffList">
    <van-sticky>
      <van-nav-bar :title="title" left-arrow @click-left="goBack">
        <template #right>
          <van-icon name="ellipsis" size="18" @click="showOverlay = true" />
        </template>
      </van-nav-bar>
    </van-sticky>

    <van-search
      v-model="keyword"
      placeholder="请按员工姓名搜索"
      show-action
      shape="round"
      @search="onSearch"
      @clear="toClearKeyWord"
    >
      <div slot="action" @click="onSearch">搜索</div>
    </van-search>

    <van-overlay :show="showOverlay" @click="showOverlay = false" class-name="over_layer">
      <van-cell-group class="layer">
        <!--  工作信息      -->
        <van-cell
          v-show="advaceInfotype === '5'"
          v-for="(item, index) in moreActionList"
          :key="item.id"
          :value="item.title"
          @click="staffRelatedActions_forWork(item)"
        />

        <!--  借支信息      -->
        <van-cell
          v-show="advaceInfotype == 1"
          v-for="(item, index) in moreActionListJZ"
          :key="index"
          :value="item.title"
          @click="staffRelatedActions(item)"
        />
        <!--  报到已读、未读、报到点名等信息      -->
        <van-cell
          v-show="advaceInfotype == 2"
          v-for="(item, index) in enroolList"
          :key="index"
          :value="item.title"
          @click="staffRelatedActions_forSignup(item)"
        />

        <!--  工资信息      -->
        <van-cell
          v-show="advaceInfotype == 3"
          v-for="(item, index) in salaryList"
          :key="index"
          :value="item.title"
          @click="staffRelatedActions(item)"
        />
      </van-cell-group>
    </van-overlay>

    <job-item-for-recruit
      :jobItem="needObj"
      :keyWord="'recruitmentManagement'"
      :routeName="$route.name"
      :searchType="1"
      :searchNameType="'0'"
      :searchVal="searchVal"
      :advaceInfotype="advaceInfotype"
    ></job-item-for-recruit>

    <van-divider :style="{color: '#1989fa', borderColor: '#1989fa', padding: '0 60px', fontWeight: 'bolder'}">
      报名员工简历
    </van-divider>

    <van-sticky :offset-top="46">
      <com-filter-menu
        v-show="advaceInfotype == 5"
        :rightOptionObj="rightOptionGZObj"
        :rightOption="rightOptionGZ"
        :rightValue="rightValue"
        @getFilterMenuValue="toGetFilterMenuValue_recruitStaff"
      ></com-filter-menu>
    </van-sticky>

    <van-sticky :offset-top="46">
      <com-filter-menu
        v-show="advaceInfotype != 1 && advaceInfotype != 3 && advaceInfotype != 5"
        :rightOptionObj="rightOptionObj"
        :rightOption="rightOptionBM"
        :rightValue="rightValue"
        @getFilterMenuValue="toGetFilterMenuValue_recruitStaff"
      ></com-filter-menu>
    </van-sticky>

    <van-sticky :offset-top="46">
      <com-filter-menu
        v-show="advaceInfotype == 1"
        :rightOptionObj="rightOptionJZObj"
        :rightOption="rightOptionJZ"
        :rightValue="rightValue"
        @getFilterMenuValue="toGetFilterMenuValue_recruitStaff"
      ></com-filter-menu>
    </van-sticky>

    <van-sticky :offset-top="46">
      <com-filter-menu
        v-show="advaceInfotype == 3"
        :rightOptionObj="rightOptionSalaryObj"
        :rightOption="rightOptionSalary"
        :rightValue="rightValue"
        @getFilterMenuValue="toGetFilterMenuValue_recruitStaff"
      ></com-filter-menu>
    </van-sticky>

    <!-- 招聘员工 -->
    <com-multiple-checkbox-card
      ref="comMultipleCheckboxCard"
      v-if="recruitStaffList"
      :dataList="recruitStaffList"
      :actionType="'add'"
      :advaceInfotype="advaceInfotype"
      :keyWord="'staffList'"
      :isRead="rightValue"
      :enroll="'1'"
      :companyID="companyID"
      :jobID="jobID"
      @sendSelectedArr="sendSelectedArr($event)"
      @setWorkload="setWorkload($event)"
      @update="update"
    ></com-multiple-checkbox-card>

    <!-- 借支 -->
    <van-popup v-model="popupShow" class="popupDiv" closeable position="bottom" :style="{height: '70%'}">
      <van-row
        class="title"
        type="flex"
        justify="space-between"
        style="border-bottom: 1px solid #eee; padding: 10px 0;"
      >
        <van-col span="6" style="padding-left: 20px">
          <van-button
            style="margin-right: 15px;"
            size="small"
            :type="btnStatus ? 'warning' : 'info'"
            @click="checkAllOrNot"
            >{{ btnStatus ? '重置' : '全选' }}
          </van-button>
        </van-col>
        <van-col span="15" style="padding-left: 20px">
          <div style="fontSize:18px;marginTop:3px">借支支付</div>
        </van-col>
      </van-row>
      <van-checkbox-group
        ref="checkboxGroup"
        v-model="lendMoneySelectedList"
        class="multiple_checkbox_card"
        @change="lendMoneyChange($event)"
      >
        <div class="popupContext">
          <van-cell class="checkbox_item" v-for="item in lendMoneyList" :key="item.id">
            <template #title>
              <div style="display:flex;margin-bottom:10px">
                <div>
                  <van-image :src="item.avatar" round cover width="1.5rem" height="1.5rem" />
                </div>
                <div style="margin-top: 6px;padding-left:10px">
                  <div style="margin-bottom:10px;text-align:left">近聘昵称：{{ item.nick_name }}</div>
                  <div>借支金额：{{ item.bill_money || 0 }}</div>
                </div>
              </div>
            </template>
            <template #right-icon>
              <van-checkbox
                :name="item"
                :disabled="!item.bill_money || item.bill_money == 0"
                shape="square"
                ref="checkboxes"
                checked-color="#FA743B"
              />
            </template>
          </van-cell>
        </div>
      </van-checkbox-group>
      <van-row class="bottom" type="flex" justify="space-between" style="border-top: 1px solid #eee; padding: 10px 0;">
        <!-- <van-col span="6" style="padding-left: 20px">
          <van-button style="margin-right: 15px;" size="small" :type="'info'" @click="popupShow = false"
            >借支人
          </van-button>
        </van-col> -->
        <van-col span="18" style="padding-left: 20px">
          <div style="fontSize:18px;marginTop:3px">借支总金额：{{ totalLendMoney }}元</div>
        </van-col>
        <van-col span="6" style="padding-left: 20px">
          <van-button style="margin-right: 15px;" size="small" :type="'info'" @click="goPayLendMoney"
            >去支付
          </van-button>
        </van-col>
      </van-row>
    </van-popup>
    <!-- 不借支 -->
    <van-popup v-model="noLendMoneyShow" class="popupDiv" closeable position="bottom" :style="{height: '70%'}">
      <van-row
        class="title"
        type="flex"
        justify="space-between"
        style="border-bottom: 1px solid #eee; padding: 10px 0;"
      >
        <van-col span="6" style="padding-left: 20px">
          <van-button
            style="margin-right: 15px;"
            size="small"
            :type="btnStatus ? 'warning' : 'info'"
            @click="checkAllOrNot"
            >{{ btnStatus ? '重置' : '全选' }}
          </van-button>
        </van-col>
        <van-col span="15" style="padding-left: 20px">
          <div style="fontSize:18px;marginTop:3px">不借支</div>
        </van-col>
      </van-row>
      <van-checkbox-group
        ref="checkboxGroup"
        v-model="noLendMoneySelectedList"
        class="multiple_checkbox_card"
        @change="noLendMoneyChange($event)"
      >
        <div class="popupContext">
          <van-cell class="checkbox_item" v-for="item in lendMoneyList" :key="item.id">
            <template #title>
              <div style="display:flex;margin-bottom:10px">
                <div>
                  <van-image :src="item.avatar" round cover width="1.5rem" height="1.5rem" />
                </div>
                <div style="margin-top: 6px;padding-left:10px">
                  <div style="margin-bottom:10px;text-align:left">近聘昵称：{{ item.nick_name }}</div>
                  <div>借支金额：{{ item.bill_money || 0 }}</div>
                </div>
              </div>
            </template>
            <template #right-icon>
              <van-checkbox
                :name="item"
                :disabled="!item.bill_money || item.bill_money == 0"
                shape="square"
                ref="checkboxes"
                checked-color="#FA743B"
              />
            </template>
          </van-cell>
        </div>
      </van-checkbox-group>
      <van-row class="bottom" type="flex" justify="end" style="border-top: 1px solid #eee; padding: 10px 0;">
        <van-col span="6" style="padding-left: 20px;">
          <van-button style="margin-right: 15px;" size="small" :type="'info'" @click="rejectLendMoney"
            >不借支</van-button
          >
        </van-col>
      </van-row>
    </van-popup>
    <!-- 支付工资 -->
    <van-popup v-model="salaryPayPopup" class="popupDiv" closeable position="bottom" :style="{height: '70%'}">
      <van-row
        class="title"
        type="flex"
        justify="space-between"
        style="border-bottom: 1px solid #eee; padding: 10px 0;"
      >
        <van-col span="6" style="padding-left: 20px">
          <van-button
            style="margin-right: 15px;"
            size="small"
            :type="salaryPayBtnStatus ? 'warning' : 'info'"
            @click="salaryPayCheckPick"
            >{{ salaryPayBtnStatus ? '重置' : '全选' }}
          </van-button>
        </van-col>
        <van-col span="15" style="padding-left: 20px">
          <div style="fontSize:18px;marginTop:3px">工资支付</div>
        </van-col>
      </van-row>
      <van-checkbox-group
        ref="salaryCheckboxGroup"
        v-model="salarymoneyPayChecked"
        @change="salarymoneyPayChange($event)"
        class="multiple_checkbox_card"
      >
        <div class="popupContext">
          <van-cell
            :class="[selectedArr.includes(item.jobuserid) ? '' : 'dispaly_none', 'checkbox_item']"
            v-for="(item, index) in recruitStaffList"
            :key="index"
          >
            <template #title v-if="selectedArr.includes(item.jobuserid)">
              <div style="display:flex;margin-bottom:10px">
                <div>
                  <van-image round cover width="1.5rem" height="1.5rem" :src="item.avatar ? item.avatar : logoImg" />
                </div>
                <div style="margin-top: 6px;padding-left:10px">
                  <div style="margin-bottom:10px;text-align:left">近聘昵称：{{ item.nick_name }}</div>
                  <div>支付金额：{{ item.salarymoney ? item.salarymoney : 0 }}</div>
                </div>
              </div>
            </template>
            <template #right-icon v-if="selectedArr.includes(item.jobuserid)">
              <van-checkbox
                shape="square"
                :name="item.jobuserid"
                :disabled="item.salarymoney == '' || item.salarymoney == 0"
                checked-color="#FA743B"
              />
            </template>
          </van-cell>
        </div>
      </van-checkbox-group>
      <van-row class="bottom" type="flex" justify="space-between" style="border-top: 1px solid #eee; padding: 10px 0;">
        <van-col span="18" style="padding-left: 20px">
          <div style="fontSize:18px;marginTop:3px">支付总金额：{{ sumPayMoney }} 元</div>
        </van-col>
        <van-col span="6" style="margin: auto 0;padding-left: 20px">
          <van-button style="margin-right: 15px;" size="small" :type="'info'" @click="goPaySalary">去支付 </van-button>
        </van-col>
      </van-row>
    </van-popup>

    <!-- 支付代招费 -->
    <van-popup v-model="feePayPopup" class="popupDiv" closeable position="bottom" :style="{height: '70%'}">
      <van-row
        class="title"
        type="flex"
        justify="space-between"
        style="border-bottom: 1px solid #eee; padding: 10px 0;"
      >
        <van-col span="6" style="padding-left: 20px">
          <van-button
            style="margin-right: 15px;"
            size="small"
            :type="feePayBtnStatus ? 'warning' : 'info'"
            @click="feePayCheckPick"
            >{{ feePayBtnStatus ? '重置' : '全选' }}
          </van-button>
        </van-col>
        <van-col span="15">
          <div style="fontSize:18px;marginTop:3px">支付代招费</div>
        </van-col>
      </van-row>
      <van-checkbox-group
        ref="feeCheckboxGroup"
        v-model="feePayChecked"
        @change="feePayChange($event)"
        class="multiple_checkbox_card"
      >
        <div class="popupContext">
          <van-cell
            :class="[selectedArr.includes(item.jobuserid) ? '' : 'dispaly_none', 'checkbox_item']"
            v-for="(item, index) in recruitStaffList"
            :key="index"
          >
            <template #title v-if="selectedArr.includes(item.jobuserid)">
              <div style="display:flex;margin-bottom:10px">
                <div style="margin:auto 0;">
                  <van-image round cover width="1.5rem" height="1.5rem" :src="item.avatar ? item.avatar : logoImg" />
                </div>
                <div style="margin-top: 6px;padding-left:10px">
                  <div style="margin-bottom:10px;text-align:left">近聘昵称：{{ item.nick_name }}</div>
                  <div>
                    类型：{{ item.generation_of_commission | formatMoney }} 元/{{
                      item.fee_unit | formatFeeUnit
                    }}
                    工作时长：{{ item.quantity ? item.quantity : 0 }}{{ item.fee_unit | formatFeeUnit }}
                  </div>
                  <div>
                    代招费：{{ item.quantity ? (item.quantity * item.generation_of_commission).toFixed(2) : 0 }} 元
                  </div>
                </div>
              </div>
            </template>
            <template #right-icon v-if="selectedArr.includes(item.jobuserid)">
              <van-checkbox
                shape="square"
                :name="item.jobuserid"
                :disabled="item.quantityHasSetted == '' || item.quantityHasSetted == 0"
                checked-color="#FA743B"
              />
            </template>
          </van-cell>
        </div>
      </van-checkbox-group>
      <van-row class="bottom" type="flex" justify="space-between" style="border-top: 1px solid #eee; padding: 10px 0;">
        <van-col span="18" style="padding-left: 20px">
          <div style="fontSize:18px;marginTop:3px">支付总金额：{{ sumPayFeeMoney }} 元</div>
        </van-col>
        <van-col span="6" style="margin: auto 0;padding-left: 20px">
          <van-button style="margin-right: 15px;" size="small" :type="'info'" @click="goPayFee">去支付 </van-button>
        </van-col>
      </van-row>
    </van-popup>
  </div>
</template>

<script>
import {Popup, Toast} from 'vant'
import comJobItem from '../../../components/comJobItem'
import jobItemForRecruit from './common/jobItemForRecruit'
import comMultipleCheckboxCard from '../companyHome/common/comMultipleCheckboxCard'
import {obj} from '../../../constants/comUtils'
import comFilterMenu from '../../../components/comFilterMenu'
import {reqGetManagement, reqSaveCompanyApplyUpdate, reqGetApply, getJobData} from '../../../api/myCompany.js'
import {formatMoney, formatFeeUnit} from '@/utils/format'
import lendMoneyDetail from '../../lendMoney/lendMoneyDetail'
import {concatIds} from '@/utils'
import {mapGetters} from 'vuex'

const rightOptionGZObj = {
  all: '全部（不限）',
  man: '男',
  woman: '女',
  job_pending: '未入职',
  employerEnterprise_noCall: '在职',
  pickUp_noCall: '自离',
  pickUp_call: '辞职',
  pickUp_calling: '辞职申请中',
  pickUp_call_may: '辞职已批准',
  pickUp_call_no: '辞职不批准'
  // job_unchecked: '工作未核对',
}
const rightOptionObj = {
  all: '全部',
  man: '男',
  woman: '女',
  read: '报名已读',
  unread: '报名未读',
  report_noCall: '报道未点名',
  report_call: '报道已点名',
  pickUp_noCall: '接送未点名',
  pickUp_call: '接送已点名',
  employerEnterprise_noCall: '到用企未点名',
  employerEnterprise_call: '到用企已点名',
  dormitory_noCall: '分宿舍未点名',
  dormitory_call: '分宿舍已点名',
  train_noCall: '培训未点名',
  train_call: '培训已点名',
  agreement_noSign: '合同协议未签',
  agreement_sign: '合同协议已签'
  // 'channel_source': '渠道来源',
}
const rightOptionJZ = [
  {text: '全部（不限）', value: 'all'},
  {text: '申请中', value: 'in_application'},
  {text: '借支', value: 'lend'},
  {text: '不借支', value: 'dont_lend'},
  {text: '男', value: 'man'},
  {text: '女', value: 'woman'},
  {text: '自离', value: 'leave'},
  {text: '辞职', value: 'resign'},
  {text: '在职', value: 'on_job'}
]
const rightOptionJZObj = {
  all: '全部（不限）',
  in_application: '申请中',
  lend: '借支',
  dont_lend: '不借支',
  man: '男',
  woman: '女',
  leave: '自离',
  resign: '辞职',
  on_job: '在职'
}
const rightOption = [
  {text: '全部（不限）', value: 'all'},
  {text: '男', value: 'Male'},
  {text: '女', value: 'Female'},
  {text: '报名未读', value: 'Unread'},
  {text: '报名已读', value: 'Read'},
  {text: '报到未点名', value: 'UnCallRoll'},
  {text: '报到已点名', value: 'CallRoll'},
  {text: '自离', value: 'Leave'},
  {text: '辞职', value: 'Resign'},
  {text: '辞职已批准', value: 'Approval'},
  {text: '辞职不批准', value: 'NonApproval'},
  {text: '在职', value: 'OnJob'}
]
const rightOptionBM = [
  {text: '全部（不限）', value: 'all'},
  {text: '男', value: 'Male'},
  {text: '女', value: 'Female'},
  {text: '报名未读', value: 'Unread'},
  {text: '报名已读', value: 'Read'},
  {text: '报到未点名', value: 'baodaoUnCallRoll'},
  {text: '报到已点名', value: 'baodaoCallRoll'},
  {text: '接送已点名', value: 'jesongCallRoll'},
  {text: '接送未点名', value: 'jesongUnCallRoll'},
  {text: '到用企未点名', value: 'daoqiUnCallRoll'},
  {text: '到用企已点名', value: 'daoqiCallRoll'},
  {text: '分宿舍未点名', value: 'dormitory_noCall'},
  {text: '分宿舍已点名', value: 'dormitory_call'},
  {text: '培训未点名', value: 'train_noCall'},
  {text: '培训已点名', value: 'train_call'},
  {text: '合同协议未签', value: 'agreement_noSign'},
  {text: '合同协议已签', value: 'agreement_sign'}
]

const rightOptionGZ = [
  {text: '全部（不限）', value: 'all'},
  {text: '男', value: 'man'},
  {text: '女', value: 'woman'},
  {text: '未入职', value: 'job_pending'},
  {text: '在职', value: 'employerEnterprise_noCall'},
  {text: '自离', value: 'pickUp_noCall'},
  {text: '辞职', value: 'pickUp_call'},
  {text: '辞职申请中', value: 'pickUp_calling'},
  {text: '辞职已批准', value: 'pickUp_call_may'},
  {text: '辞职不批准', value: 'pickUp_call_no'}
  /*{text: '工作未核对', value: 'job_unchecked'}*/
]

const rightOptionSalary = [
  {text: '全部（不限）', value: 'all'},
  {text: '工资待付', value: 'salary_to_pay'},
  {text: '代招费待付', value: 'fee_to_pay'},
  {text: '男', value: 'man'},
  {text: '女', value: 'woman'},
  {text: '自离', value: 'leave'},
  {text: '辞职', value: 'resign'},
  {text: '在职', value: 'on_job'}
]
const rightOptionSalaryObj = {
  all: '全部（不限）',
  salary_to_pay: '工资待付',
  fee_to_pay: '代招费待付',
  man: '男',
  woman: '女',
  leave: '自离',
  resign: '辞职',
  on_job: '在职'
}

export default {
  name: 'recruitStaffList',
  components: {
    comMultipleCheckboxCard,
    comJobItem,
    comFilterMenu,
    'van-popup': Popup,
    jobItemForRecruit
  },
  computed: {
    ...mapGetters(['allUserInfo']),

    searchVal() {
      return this.$route.query.searchVal
    }
  },
  data() {
    const needJobObj = this.$route.query.data
    return {
      title: '',
      rightValue: 'all',
      popupShow: false,
      noLendMoneyShow: false,
      btnStatus: false,
      rightOption,
      rightOptionJZObj,
      rightOptionJZ,
      rightOptionBM,
      rightOptionGZ,
      rightOptionGZObj,
      rightOptionObj,
      rightOptionSalary,
      rightOptionSalaryObj,
      advaceInfotype: '',
      showOverlay: false,
      isSearchBoxShow: false,
      needObj: needJobObj ? JSON.parse(needJobObj) : {},
      selectedArr: [],
      companyID: '',
      jobID: '',
      enroolList: [
        {
          id: '3',
          title: '报名已读'
        },
        {
          id: '4',
          title: '报名未读'
        },
        {
          id: '5',
          title: '招聘统计'
        },
        {
          id: '6',
          title: '报到点名'
        },
        {
          id: '7',
          title: '接送点名'
        },
        {
          id: '8',
          title: '到用企点名'
        },
        {
          id: '9',
          title: '分宿舍点名'
        },
        {
          id: '10',
          title: '培训点名'
        },
        {
          id: '11',
          title: '合同协议'
        }
      ],
      moreActionList: [
        {
          id: '3',
          title: '在职'
        },
        {
          id: '4',
          title: '辞职'
        },
        {
          id: '5',
          title: '自离'
        },
        {
          id: '6',
          title: '辞职批准'
        },
        {
          id: '7',
          title: '辞职不批准'
        }
      ],
      moreActionListJZ: [
        {
          id: '3',
          title: '借支'
        },
        {
          id: '4',
          title: '不借支'
        }
      ],
      salaryList: [
        {
          id: '3',
          title: '支付工资'
        },
        {
          id: '4',
          title: '支付代招费'
        }
      ],
      recruitStaffList: [],

      searchType: false, // 工资信息页搜索可见
      keyword: '', // 工资信息页搜索关键词

      salaryPayPopup: false, // 支付工资弹窗
      salaryPayBtnStatus: false, // 支付工资全选
      sumPayMoney: 0, // 工资总支付金额
      salarymoneyPayChecked: [], // 勾选要支付的工资条
      salaryinfoidPayChecked: [], // 勾选要支付的工资条
      totalLendMoney: 0, // 借支总金额
      lendMoneyList: [],
      noLendMoneyList: [], // 不借支
      lendMoneySelectedList: [], // 已选中的借支列表
      noLendMoneySelectedList: [], // 已选中的不借支列表

      feePayPopup: false, // 支付代招费弹窗
      feePayBtnStatus: false, // 支付代招费全选
      sumPayFeeMoney: 0, // 代招费总支付金额
      feePayChecked: [], // 勾选要支付的代招费
      feePayJobUserIdList: [] // 勾选要支付的代招费
    }
  },
  watch: {
    /*
     * 筛选值的变化就发起请求
     *
     * */
    rightValue(curVal, oldVal) {
      this.getData()
    }
  },
  created() {
    // 参数校验下
    if (this.$route.query.jobInfoId) {
      this.jobID = this.$route.query.jobInfoId
      // 更新
      this.advaceInfotype = this.$route.query.advaceInfoType
    } else {
      this.$router.back()
      Toast('参数丢失！')
    }
  },

  mounted() {
    // 员工列表
    this.getData()
    // 职位详情，包含已读、未读辞职人数等信息
    this._getJobDetail()
    // 获取借支信息
    this.getUserApplyAdvance()
  },
  /*activated() {
    this.keyword = ''
    this.searchType = false
    this.salaryPayPopup = false
    this.salaryPayBtnStatus = false
    this.sumPayMoney = 0
    this.salarymoneyPayChecked = []
    this.salaryinfoidPayChecked = []

    this.feePayPopup = false
    this.feePayBtnStatus = false
    this.sumPayFeeMoney = 0
    this.feePayChecked = []
    this.feePayJobUserIdList = []
  },

  deactivated() {
    //销毁缓存页面--
    if (this.advaceInfotype != 3) {
      // 工资信息员工管理 不销毁页面
      this.$destroy('recruitStaffList')
    }
    // else {
    //   console.log("工资信息员工管理 不销毁页面")
    // }
  },*/

  methods: {
    fetchData() {
      console.log('router' + this.$route)
      // 解决路由切换，页面不更新的实用方法
      if (this.$route.path == '/recruitStaffList') {
        // 请求数据的方法
        console.log('不刷新')
      } else {
        console.log('不刷新')
      }
    },
    goBack() {
      if (this.$route.query.advaceInfoType == 3) {
        // 工资信息员工管理 返回到工资列表页
        this.$router.push({
          path: '/myCompany/salary'
        })
      } else if (this.$route.query.advaceInfoType == 2) {
        this.$router.push({
          path: '/myCompany/recruitmentManagement'
        })
      } else if (this.$route.query.advaceInfoType == 5) {
        this.$router.push({
          path: '/myCompany/workInfo'
        })
      } else if (this.$route.query.advaceInfoType == 1) {
        this.$router.push({
          path: '/myCompany/advaceInfo'
        })
      } else {
        console.log(this.$route.query.advaceInfoType)
      }
    },
    async rejectLendMoney() {
      const jobUserIds = this.noLendMoneySelectedList.filter(x => x.bill_money && x.bill_money > 0).map(x => x.user_id)

      if (jobUserIds.length == 0) {
        Toast('请勾选拒绝借支的申请信息!')
        return
      }

      let params = {
        jobUserIdList: concatIds(jobUserIds),
        jobId: this.noLendMoneySelectedList[0].job_id
      }

      this.$api.myCompany.reqRejectLendMoney(params).then(res => {
        if (res.code === 200) {
          Toast.success('拒绝借支成功')
          setTimeout(() => {
            this.noLendMoneyShow = false
            this.getData()
          }, 1000)
        } else {
          Toast('操作失败请重试！')
        }
      })
    },
    async goPayLendMoney() {
      if (this.totalLendMoney == 0) {
        Toast('请勾选需要支付的借支的申请信息!')
        return
      }

      const billIds = this.lendMoneySelectedList.filter(x => x.bill_money && x.bill_money > 0).map(x => x.bill_id)
      const jobUserIds = this.lendMoneySelectedList.filter(x => x.bill_money && x.bill_money > 0).map(x => x.user_id)

      // 校验余额是否够支付
      const res = await this.$api.job.getFinance()
      if (res.code === 200) {
        let caip = res.data.fina.caip || 0 // 余额，乘以1000
        if (caip < this.totalLendMoney * 1000) {
          Toast('您当前余额不足，请先充值！')
          return
        } else {
          this.$router.push({
            name: 'lendMoneyPay',
            query: {
              money: this.totalLendMoney,
              jobId: this.lendMoneySelectedList[0].job_id,
              billIds: billIds.join(','),
              jobUserIds: jobUserIds.join(',')
            }
          })
        }
      } else {
        Toast('操作失败请重试！')
      }
    },
    async goPaySalary() {
      if (this.sumPayMoney == 0) {
        Toast('请勾选需要支付的工资信息!')
        return
      }

      // 校验余额是否够支付
      const res = await this.$api.job.getFinance()
      if (res.code === 200) {
        let caip = res.data.fina.caip || 0 // 余额，乘以1000
        if (caip < this.sumPayMoney * 1000) {
          Toast('您当前余额不足，请先充值！')
          return
        } else {
          this.$router.push({
            name: 'salaryPay',
            query: {
              money: this.sumPayMoney,
              salaryinfoidList: this.salaryinfoidPayChecked.join(',')
            }
          })
        }
      } else {
        Toast('操作失败请重试！')
      }
    },
    async goPayFee() {
      if (this.sumPayFeeMoney == 0) {
        Toast('请勾选需要支付的代招费记录!')
        return
      }

      let jobUserIdList = []
      for (let jobuserid of this.feePayChecked) {
        for (let staff of this.recruitStaffList) {
          if (jobuserid === staff.jobuserid && staff.quantity && staff.quantity * staff.generation_of_commission > 0) {
            jobUserIdList.push(jobuserid)
            break
          }
        }
      }

      // 校验余额是否够支付
      const res = await this.$api.job.getFinance()
      if (res.code === 200) {
        let caip = res.data.fina.caip || 0 // 余额，乘以1000
        if (caip < this.sumPayFeeMoney * 1000) {
          Toast('您当前余额不足，请先充值！')
          return
        } else {
          this.$router.push({
            name: 'feePay',
            query: {
              money: this.sumPayFeeMoney,
              jobId: this.jobID,
              jobUserIdList: jobUserIdList.join(',')
            }
          })
        }
      } else {
        Toast('操作失败请重试！')
      }
    },
    checkAllOrNot() {
      this.$refs.checkboxGroup.toggleAll(!this.btnStatus)
      this.btnStatus = !this.btnStatus
    },
    update() {
      // 更新表单的数据
      this.getData()
      this._getJobDetail()
      // 筛选条的变化, 取消选中
      this.$refs.comMultipleCheckboxCard.checkAllOrNot()
    },

    async _getJobDetail() {
      // 职位详情数据
      let resultDetail = await getJobData(this.jobID)
      if (resultDetail.code === 200) {
        this.needObj = resultDetail.data
      }
    },

    async getData() {
      // job_id
      let id = this.$route.query.jobInfoId
      let uid = this.$route.query.advaceInfoType

      if (uid == 2) {
        this.title = '报名信息员工管理'
        const res = await reqGetManagement({
          JobId: id,
          // 筛选条件
          condition: this.rightValue,
          keyword: this.keyword,
          qudao_emp_name: this.$route.query.searchVal
        })
        if (res.code === 200) {
          // 员工管理的列表
          this.recruitStaffList = res.data.applist
        }
      } else if (uid == 1) {
        this.title = '借支信息员工管理'
        const res = await this.$api.myCompany.reqGetAdvanceBill({
          JobId: this.$route.query.jobInfoId,
          searchType: this.rightValue, // 筛选条件
          keyword: this.keyword
        })
        this.companyID = this.allUserInfo.company_id
        if (res.code === 200) {
          // 员工管理的列表
          this.recruitStaffList = res.data.applylist
        }
      } else if (uid == 3) {
        this.title = '工资信息员工管理'

        this.companyID = this.allUserInfo.company_id
        this.jobID = this.$route.query.jobInfoId
        const dataList = await this.$api.myCompany.reqGetSalaryInfo({
          jobId: this.$route.query.jobInfoId,
          CompanyId: this.allUserInfo.company_id,
          searchType: this.rightValue, // 筛选条件
          keyword: this.keyword
        })

        this.recruitStaffList = dataList.data.userlist
        for (let i = 0; i < this.recruitStaffList.length; i++) {
          let quantity = this.recruitStaffList[i].quantity
            ? parseFloat(this.recruitStaffList[i].quantity).toFixed(2)
            : ''
          this.recruitStaffList[i].quantity = quantity
          this.recruitStaffList[i].quantityInput = quantity
          this.recruitStaffList[i].quantityHasSetted = quantity ? 1 : 0
        }
      } else {
        this.title = '工作信息员工管理'
        const dataList = await this.$api.job.getJobInfoStaff({
          JobId: this.$route.query.jobInfoId,
          condition: this.rightValue,
          keyword: this.keyword
        })
        this.recruitStaffList = dataList.data.applylist
      }
    },
    async getUserApplyAdvance() {
      for (let index in this.lendMoneyList) {
        let params = {
          CompanyID: this.allUserInfo.company_id,
          UserId: this.lendMoneyList[index]['user_id'],
          PositionId: this.$route.query.jobInfoId
        }
        // 循环请求借款金额
        this.$api.myCompany.getUserApplyAdvance(params).then(res => {
          if (res.code === 200) {
            console.log(res)
          } else {
            console.log(res)
          }
        })
      }
    },
    sendSelectedArr(data) {
      // 获取多选中的值
      console.log('父组件中---获取多选中的值', data)
      this.selectedArr = data
      this.selectedArr_forRecruit = data
      this.lendMoneyList = data
      this.noLendMoneyList = data
    },
    goNeedPage_recruitStaff(val) {
      // '工资信息员工管理页'在本页搜索不做页面跳转
      if (this.advaceInfotype == 3) {
        this.searchType = !this.searchType
      } else {
        const keyWord = 'username'
        if (val === 'search') {
          this.$router.push({
            path: `/searchRecords/${keyWord}`
          })
        }
      }
    },

    handleSearchBoxShow() {
      this.isSearchBoxShow = !this.isSearchBoxShow
      this.keyword = ''
    },
    toGetFilterMenuValue_recruitStaff(val) {
      // 控制筛选条的变化
      console.log('筛选条的变化', val)
      this.rightValue = val
      // 筛选条的变化, 取消选中项
      this.$refs.comMultipleCheckboxCard.checkAllOrNot()
    },

    // 报名信息 的 相关操作
    async staffRelatedActions_forSignup(item) {
      // 计数从3开始的
      // console.log('报名信息的操作', item.title);
      if (['3', '4'].includes(item.id)) {
        if (this.selectedArr_forRecruit && this.selectedArr_forRecruit.length) {
          // 操作已读和未读
          let params = {
            jobId: this.jobID,
            appid: this.selectedArr_forRecruit.join(','),
            // 3的参数是1, 4的参为0。（也就是说：0.报名未读， 1.报名已读；）
            appstate: item.id === '3' ? '1' : '0'
          }
          const res = await reqSaveCompanyApplyUpdate(params)
          if (res.code === 200) {
            Toast.success('操作成功!')
            this.getData()
            this._getJobDetail()
            // 取消选中项
            this.$refs.comMultipleCheckboxCard.checkAllOrNot()
          }
        } else {
          Toast('请至少选择一项！')
          return null
        }
      } else {
        // 操作其他，例如：报到码
        console.log(item)
        console.log(this.needObj)
        this.$router.push({
          path: '/myCompany/staffRollCall',
          query: {
            // 将传递的对象解析为字符串
            itemObj: JSON.stringify(item),
            type: Number(item.id) - 5,
            job_id: this.needObj.id,
            // data: this.$route.query.data,
            data: JSON.stringify(this.needObj) || this.$route.query.data
          }
        })
      }
    },

    // 工作信息 的 相关操作
    async staffRelatedActions_forWork(item) {
      console.log('工作信息', item.title)
      if (this.selectedArr_forRecruit && this.selectedArr_forRecruit.length) {
        //
        let itemObj = {
          3: 'OnJob',
          4: 'Resign',
          5: 'Leave',
          6: 'Approval',
          7: 'NonApproval'
        }

        // 操作
        const params_work = {
          condition: itemObj[item.id],
          JobId: this.$route.query.jobInfoId,
          // 多选中的值
          UserList: this.selectedArr_forRecruit,
          Value: ''
        }
        // this.getData()
        const res = await this.$api.job.getEidtJobInformation(params_work)

        console.log('响应值', res)
        if (res.code === 200) {
          Toast.success('操作成功!')
          this.getData()
          this._getJobDetail()
          // 取消选中项
          this.$refs.comMultipleCheckboxCard.checkAllOrNot()
        }
      } else {
        Toast('请至少选择一项！')
        return null
      }
    },

    async staffRelatedActions(item) {
      /*
       * 报名信息 （已抽离 为 staffRelatedActions_forSignup）
       * */
      if (this.advaceInfotype == 2) {
        if (item.id === '1') {
          console.log('短信---可群发', item.id)
        } else if (item.id === '2') {
          // this.$router.push('/customerService')
        } else if (item.id === '3') {
          let params = {
            appid: this.selectedArr.join(),
            appstate: 1
          }
          const res = await reqSaveCompanyApplyUpdate(params)
          if (res.code == 200) {
            this.getData()
          }
        } else if (item.id === '4') {
          let params = {
            appid: this.selectedArr.join(),
            appstate: 0
          }
          const res = await reqSaveCompanyApplyUpdate(params)
          if (res.code == 200) {
            this.getData()
          }
        } else {
          console.log('其他操作', item.id)
          console.log(this.$route.query)
          this.$router.push({
            path: '/myCompany/staffRollCall',
            query: {
              // 将传递的对象解析为字符串
              itemObj: JSON.stringify(item),
              type: Number(item.id) - 5,
              job_id: this.needObj.id,
              data: this.$route.query.data
            }
          })
        }
      }

      /*
       * 工作信息 已抽离 为 staffRelatedActions_forWork）
       *
       * */
      if (this.advaceInfotype == 5) {
        let itemObj = {
          3: 'OnJob',
          4: 'Resign',
          5: 'Leave',
          6: 'Approval',
          7: 'NonApproval'
        }
        const params = {
          condition: itemObj[item.id],
          JobId: this.$route.query.jobInfoId,
          UserList: this.selectedArr_forRecruit.join(','),
          Value: ''
        }
        await this.$api.job.getEidtJobInformation(params)
        this.getData()
      }

      /*
       * 借支信息
       * */
      if (this.advaceInfotype == 1) {
        // 借支
        if (item.id == '3') {
          // 借支
          this.popupShow = true

          let sumLendMoney = 0
          let selectedList = []
          for (let item of this.lendMoneyList) {
            if (item.bill_money && item.bill_money > 0) {
              sumLendMoney = Number(sumLendMoney) + Number(item.bill_money)
              selectedList.push(item)
            }
          }
          this.totalLendMoney = sumLendMoney
          this.lendMoneySelectedList = selectedList
        }
        if (item.id == '4') {
          // 不借支
          this.noLendMoneyShow = true

          let selectedList = []
          for (let item of this.lendMoneyList) {
            if (item.bill_money && item.bill_money > 0) {
              selectedList.push(item)
            }
          }
          this.noLendMoneySelectedList = selectedList
        }
      }

      /*
       * 工资信息
       *
       * */
      if (this.advaceInfotype == 3) {
        // 工资信息
        if (item.id === '1') {
          // 短信联系
          console.log('短信联系', item.id)
        } else if (item.id === '2') {
          // 平台联系
          console.log('平台联系', item.id)
        } else if (item.id === '3') {
          // 支付工资
          this.salaryPayPopup = true

          let sumPayMoney = 0
          let salaryinfoidList = []
          let salarymoneyPayChecked = []
          for (let jobuserid of this.selectedArr) {
            for (let staff of this.recruitStaffList) {
              if (jobuserid === staff.jobuserid && Number(staff.salarymoney) > 0) {
                sumPayMoney = Number(staff.salarymoney) + Number(sumPayMoney)
                salaryinfoidList.push(staff.salaryinfoid)
                salarymoneyPayChecked.push(jobuserid)
                break
              }
            }
          }
          this.sumPayMoney = sumPayMoney
          this.salaryinfoidPayChecked = salaryinfoidList
          this.salarymoneyPayChecked = salarymoneyPayChecked
        } else if (item.id === '4') {
          // 支付代招费
          this.feePayPopup = true

          let sumPayFeeMoney = 0
          let feePayChecked = []
          for (let jobuserid of this.selectedArr) {
            for (let staff of this.recruitStaffList) {
              if (
                jobuserid === staff.jobuserid &&
                staff.quantity &&
                staff.quantity * staff.generation_of_commission > 0
              ) {
                sumPayFeeMoney =
                  Number(sumPayFeeMoney) + Number((staff.quantity * staff.generation_of_commission).toFixed(2))
                feePayChecked.push(jobuserid)
                break
              }
            }
          }
          this.sumPayFeeMoney = sumPayFeeMoney
          this.feePayChecked = feePayChecked
          this.feePayJobUserIdList = feePayChecked
        }
      }
    },

    // 工资支付全选勾选
    salaryPayCheckPick() {
      this.salaryPayBtnStatus = !this.salaryPayBtnStatus
      if (this.salaryPayBtnStatus) {
        this.$refs.salaryCheckboxGroup.toggleAll(true)
      } else {
        this.$refs.salaryCheckboxGroup.toggleAll(false)
      }
    },
    lendMoneyChange(selectList) {
      if (selectList.length == 0) {
        this.totalLendMoney = 0
        return
      }
      let totalLendMoney = 0
      for (let item of selectList) {
        if (item.bill_money && item.bill_money > 0) {
          totalLendMoney = Number(item.bill_money) + Number(totalLendMoney)
        }
      }
      this.totalLendMoney = totalLendMoney
    },
    // 不借支列表
    noLendMoneyChange(selectList) {
      this.noLendMoneySelectedList = selectList
    },
    // 工资支付复选勾选
    salarymoneyPayChange(selectList) {
      if (selectList.length == 0) {
        this.sumPayMoney = 0
        this.salaryinfoidPayChecked = []
        return
      }

      let sumPayMoney = 0
      let salaryinfoidList = []
      for (let selectStaff of selectList) {
        for (let staff of this.recruitStaffList) {
          if (selectStaff === staff.jobuserid) {
            sumPayMoney = Number(staff.salarymoney) + Number(sumPayMoney)
            salaryinfoidList.push(staff.salaryinfoid)
            break
          }
        }
      }
      this.sumPayMoney = sumPayMoney
      this.salaryinfoidPayChecked = salaryinfoidList
    },

    // 提交工作时长
    setWorkload(params) {
      this.$api.myCompany.setWorkload(params).then(res => {
        if (res.code === 200 && res.data.success == 1) {
          Toast('提交成功!')
          this.setWorkloadFiled(params.JobUserId, params.Quantity)
        } else if (res.data.success == 0) {
          Toast(res.data.msg)
        } else {
          Toast('操作失败请重试！')
        }
      })
    },

    setWorkloadFiled(jobUserId, quantity) {
      let index = -1
      for (let i = 0; i < this.recruitStaffList.length; i++) {
        if (this.recruitStaffList[i].jobuserid === jobUserId) {
          index = i
          break
        }
      }

      if (index >= 0) {
        this.$set(this.recruitStaffList[index], 'quantityHasSetted', 1)
        this.$set(this.recruitStaffList[index], 'quantity', quantity)
        // quantityInput
      }
    },

    // 代招费支付全选勾选
    feePayCheckPick() {
      this.feePayBtnStatus = !this.feePayBtnStatus
      if (this.feePayBtnStatus) {
        this.$refs.feeCheckboxGroup.toggleAll(true)
      } else {
        this.$refs.feeCheckboxGroup.toggleAll(false)
      }
    },

    // 代招费支付复选勾选
    feePayChange(selectList) {
      if (selectList.length == 0) {
        this.sumPayFeeMoney = 0
        return
      }

      let sumPayFeeMoney = 0
      let feePayJobUserIdList = []
      for (let selectStaff of selectList) {
        for (let staff of this.recruitStaffList) {
          if (
            selectStaff === staff.jobuserid &&
            staff.quantity &&
            staff.quantity * staff.generation_of_commission > 0
          ) {
            sumPayFeeMoney =
              Number(sumPayFeeMoney) + Number((staff.quantity * staff.generation_of_commission).toFixed(2))
            feePayJobUserIdList.push(selectStaff)
            break
          }
        }
      }
      this.sumPayFeeMoney = sumPayFeeMoney
      this.feePayJobUserIdList = feePayJobUserIdList
    },

    // 工资信息员工管理页，按员工姓名搜索
    onSearch() {
      if (this.keyword.trim()) {
        this.getData()
      } else {
        Toast('请先输入！')
      }
    },

    toClearKeyWord() {
      this.keyword = ''
      this.$nextTick(() => {
        this.getData()
      })
    }
  },

  filters: {
    formatMoney(money) {
      return formatMoney(money)
    },
    formatFeeUnit(feeUnit) {
      return formatFeeUnit(feeUnit)
    }
  }
}
</script>

<style lang="scss" scoped>
.page_recruitStaffList {
  width: 100%;
  min-height: 100vh;
  .over_layer {
    margin-top: 46px;
    height: 100%;
    z-index: 9999;
    .layer {
      width: 40%;
      font-size: 14px;
      position: absolute;
      right: 0;
      z-index: 9999;
    }
  }

  /deep/ .van-divider {
    margin: 10px 0;
  }
  /deep/.popupDiv {
    // position: absolute;
    .title {
      position: absolute;
      top: 0;
      z-index: 1;
      width: 100%;
    }
    .bottom {
      position: fixed;
      bottom: 0;
      z-index: 1000;
      width: 100%;
      background: #fff;
    }
    .popupContext {
      margin-top: 50px;
      margin-bottom: 50px;
      // max-height: 350px;
      overflow-y: scroll;
    }
  }
}

.dispaly_none {
  display: none;
}
</style>
